#ifndef CACHEUPDATEWIDGET_H
#define CACHEUPDATEWIDGET_H

#include <QItemDelegate>
#include <QTextDocument>
#include <QWidget>

#include <QApt/Globals>

class QLabel;
class QListView;
class QProgressBar;
class QStandardItemModel;
class QPushButton;

namespace QApt {
class Transaction;
class DownloadProgress;
}

namespace Ui {
class CacheUpdateWidget;
}

class CacheUpdateWidget : public QWidget
{
    Q_OBJECT

public:
    explicit CacheUpdateWidget(QWidget *parent = nullptr);
    ~CacheUpdateWidget();

    void clear();
    void setTransaction(QApt::Transaction *trans);

protected:
    void changeEvent(QEvent *e);

private slots:
    void onTransactionStatusChanged(QApt::TransactionStatus status);
    void progressChanged(int progress);
    void downloadProgressChanged(const QApt::DownloadProgress &progress);
    void updateDownloadSpeed(quint64 speed);
    void updateETA(quint64 ETA);
    void addItem(const QString &message);

signals:
    void cancelCacheUpdate();

private:
    Ui::CacheUpdateWidget *ui;

    QLabel *m_headerLabel;
    QListView *m_downloadView;
    QStandardItemModel *m_downloadModel;
    QProgressBar *m_totalProgress;
    QLabel *m_downloadSpeedLabel;
    QLabel *m_ETALabel;
    QPushButton *m_cancelButton;

    QApt::Transaction *m_trans;
    QStringList m_downloads;
    int m_lastRealProgress;
};

#endif // CACHEUPDATEWIDGET_H
